import java.util.Arrays;

//二维数组
public class Test {
    public static void main(String[] args) {
        int [][] arr={{1,2},{3,4},{5,6}};
        //打印二维数组
        System.out.println("打印二维数组");
        System.out.println("1、用Arrays.deepToSrting");
        System.out.println(Arrays.deepToString(arr));

        System.out.println("2、用for循环打印");
        for (int i = 0; i < arr.length; i++) {   //二维数组中arr.length表示行数,arr[i].length表示列数
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("3、foreach打印");
        for (int[] array : arr) {
            for (int x : array) {
                System.out.print(x+" ");
            }
            System.out.println();
        }
        //java二维数组特征
        System.out.println("java中行不能省，列可以省略\n例子：");
        int[][] arrs = new int[2][]; //定义,new int[][],初始化,只能进行两样
        System.out.println("在不指定列时二维数组每一行都是null");
        System.out.println(Arrays.deepToString(arrs));

        System.out.println("给每一行一个一维数组后有确定的列");
        arrs[0] = new int[]{1,2,3,4};
        arrs[1] = new int[]{1,3,5};
        System.out.println(Arrays.deepToString(arrs));

    }
}
